#include "contralswitch.h"


uint8_t tx_address0[5] = {0xc1,0xcc,0xcc,0xcc,0xcc};
uint8_t tx_address1[5] = {0xc2,0xcc,0xcc,0xcc,0xcc};
uint8_t tx_address2[5] = {0xc2,0xcc,0xcc,0xcc,0xcc};
uint8_t tx_address3[5] = {0xc3,0xcc,0xcc,0xcc,0xcc};
uint8_t tx_address4[5] = {0xc4,0xcc,0xcc,0xcc,0xcc};
uint8_t tx_address5[5] = {0xc5,0xcc,0xcc,0xcc,0xcc};

/*切换发送地址
 *param:sendtimes 每个设备发送次数
 *param:devnum 设备个数
*/
void switchaddress(uint8_t sendtimes,uint8_t devnum)
{
    static uint8_t num,dev;
    num++;
    if(num>sendtimes-1)
    {
        num=0;
        dev++;
        if(dev>=devnum)
        {
            dev=0;
        }
    }

    if(num==0)
    {
        if(dev==0)
        {
            xn297lWriteBuf(W_REGISTER + TX_ADDR, tx_address0, sizeof(tx_address0));
            xn297lWriteBuf(W_REGISTER + RX_ADDR_P0,tx_address0, sizeof(tx_address0));
        }
        else if(dev==1)
        {
            xn297lWriteBuf(W_REGISTER + TX_ADDR, tx_address1, sizeof(tx_address1));
            xn297lWriteBuf(W_REGISTER + RX_ADDR_P0,tx_address1, sizeof(tx_address1));
        }
        else if(dev==2)
        {
            xn297lWriteBuf(W_REGISTER + TX_ADDR, tx_address2, sizeof(tx_address2));
            xn297lWriteBuf(W_REGISTER + RX_ADDR_P0,tx_address2, sizeof(tx_address2));
        }
        else if(dev==3)
        {
            xn297lWriteBuf(W_REGISTER + TX_ADDR, tx_address3, sizeof(tx_address3));
            xn297lWriteBuf(W_REGISTER + RX_ADDR_P0,tx_address3, sizeof(tx_address3));
        }
        else if(dev==4)
        {
            xn297lWriteBuf(W_REGISTER + TX_ADDR, tx_address4, sizeof(tx_address4));
            xn297lWriteBuf(W_REGISTER + RX_ADDR_P0,tx_address4, sizeof(tx_address4));
        }
        else if(dev==5)
        {
            xn297lWriteBuf(W_REGISTER + TX_ADDR, tx_address5, sizeof(tx_address5));
            xn297lWriteBuf(W_REGISTER + RX_ADDR_P0,tx_address5, sizeof(tx_address5));
        } 
        else
        {
            ;
        }
    }
}